package com.fyGame.fyMap
{
	import flash.utils.*;
	
	public class FyMapInfo extends Object
	{
		public var mapId:int;
		public var pieceWidth:int;
		public var pieceHeight:int;
		public var gridXNum:int;
		public var gridYNum:int;
		public var gridWidth:int;
		public var gridHeight:int;
		public var connectedPointY:int;
		public var mapData:Array;
		
		public function FyMapInfo()
		{
			this.mapData = new Array();
			
		}
		
		public function read(param1:ByteArray, param2:Boolean = true) : void
		{
			var _loc_5:Array = null;
			var _loc_6:int = 0;
			var _loc_7:int = 0;
			if (param2)
			{
				param1.uncompress();
			}
			param1.endian = Endian.LITTLE_ENDIAN;
			this.mapId = param1.readInt();
			this.pieceWidth = param1.readInt();
			this.pieceHeight = param1.readInt();
			this.gridXNum = param1.readInt();
			this.gridYNum = param1.readInt();
			this.gridWidth = param1.readInt();
			this.gridHeight = param1.readInt();
			this.connectedPointY = param1.readInt();
			var _loc_3:* = this.readSize(param1);
			var _loc_4:int = 0;
			while (_loc_4 < _loc_3)
			{
				
				_loc_5 = new Array();
				_loc_6 = this.readSize(param1);
				_loc_7 = 0;
				while (_loc_7 < _loc_6)
				{
					
					_loc_5[_loc_7] = param1.readByte();
					_loc_7++;
				}
				this.mapData[_loc_4] = _loc_5;
				_loc_4++;
			}
			
		}
		
		public function write(param1:Boolean = true) : ByteArray
		{
			var _loc_3:Array = null;
			var _loc_5:int = 0;
			var _loc_2:* = new ByteArray();
			_loc_2.endian = Endian.LITTLE_ENDIAN;
			_loc_2.writeInt(this.mapId);
			_loc_2.writeInt(this.pieceWidth);
			_loc_2.writeInt(this.pieceHeight);
			_loc_2.writeInt(this.gridXNum);
			_loc_2.writeInt(this.gridYNum);
			_loc_2.writeInt(this.gridWidth);
			_loc_2.writeInt(this.gridHeight);
			_loc_2.writeInt(this.connectedPointY);
			this.writeSize(_loc_2, this.mapData.length);
			var _loc_4:int = 0;
			while (_loc_4 < this.mapData.length)
			{
				
				_loc_3 = this.mapData[_loc_4];
				this.writeSize(_loc_2, _loc_3.length);
				_loc_5 = 0;
				while (_loc_5 < _loc_3.length)
				{
					
					_loc_2.writeByte(_loc_3[_loc_5]);
					_loc_5++;
				}
				_loc_4++;
			}
			if (param1)
			{
				_loc_2.compress();
			}
			return _loc_2;
		}
		
		public function writeSize(param1:ByteArray, param2:int) : void
		{
			if (param2 < 255)
			{
				param1.writeByte(param2);
			}
			else
			{
				param1.writeByte(255);
				param1.writeInt(param2);
			}
			
		}
		
		public function readSize(param1:ByteArray) : int
		{
			var _loc_2:* = param1.readUnsignedByte();
			if (_loc_2 == 255)
			{
				return param1.readInt();
			}
			return _loc_2;
		}
		
	}
}
